package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class WaitConn implements Runnable {

    int porta;
    ServerSocket serv = null;
    Socket s = null;

    public WaitConn(int porta) {
        this.porta = porta;
    }

    public void run() {
        try {
            //Wait connection
            serv = new ServerSocket(porta);
            s = serv.accept();

            AtendeEscritor doComms = new AtendeEscritor(s);

            Thread t = new Thread(doComms);
            t.start();
            try {
                t.join();
            } catch (InterruptedException ex) {
                Logger.getLogger(WaitConn.class.getName()).log(Level.SEVERE, null, ex);
            }
            s.close();
            serv.close();

        } catch (IOException ex) {
            Logger.getLogger(WaitConn.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
